// 最小栈
// Created by madison on 2022/9/19.
//

#include "stack"

using namespace std;

// 方法一：辅助栈
class MinStack {
    stack<int> x_stack;
    stack<int> min_stack;
public:
    MinStack() {
        min_stack.push(INT_MAX);
    }

    void push(int val) {
        x_stack.push(val);
        min_stack.push(min(min_stack.top(), val));
    }

    void pop() {
        x_stack.pop();
        min_stack.pop();
    }

    int top() {
        return x_stack.top();
    }

    int getMin() {
        return min_stack.top();
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */

int main() {
    MinStack *obj = new MinStack();
    obj->push(5);
    obj->push(6);
    obj->push(2);
    obj->push(8);
    obj->pop();
    int param_3 = obj->top();
    int param_4 = obj->getMin();
    printf("%d\n", param_3);
    printf("%d\n", param_4);
    return 0;
}